﻿using System;
using System.Threading;

namespace Numble
{
    class NameGame
    {
        public static Random next = new Random();

        public static void Name(int size, int time)
        {
            int heigth = 0;
            int column = size + 3;

            PrintN(size, heigth, column);

            heigth += size;
            column += 0;
            PrintU(size, heigth, column);

            heigth += size;
            column += 0;
            PrintM(size, heigth, column);

            heigth += size;
            column += 0;
            PrintB(size - 2, heigth, column);
            int colRaven = column + 6;
            Raven(size, heigth, colRaven);


            heigth += size - 3;
            column += 0;
            PrintL(size - 2, heigth, column);

            heigth += size - 3;
            column += 0;
            PrintE(size - 2, heigth, column);
            Thread.Sleep(3 * time);
            Console.Clear();
        }

        public static void Raven(int n, int heigth, int column)
        {
            Console.SetCursorPosition(heigth, column++);
            Console.WriteLine(" R A V E N");
        }

        private static void PrintN(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];
            Console.ForegroundColor = ConsoleColor.Blue;

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (col == 0 || col == matrix.GetLength(1) - 1 || row - col == 1)
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }

        static void PrintU(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            Console.ForegroundColor = ConsoleColor.Cyan;

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (
                        (col == 0 && row >= 0 && row < n - 1) ||
                        (col == matrix.GetLength(1) - 1 && row >= 0 && row < n - 1) ||
                        (row == n - 1 && col >= 1 && col < (n - 2) - 1)
                    )
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }

        static void PrintM(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            Console.ForegroundColor = ConsoleColor.Green;

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if ((col == 0 || col == matrix.GetLength(1) - 1) || ((row >= 1 && row <= (n - 2) / 2) && (row - col == 0 || row + col == n - 3)) || (row == n / 2 && col == (n - 2) / 2))
                    {
                        int num = next.Next(0, 10);

                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }

        static void PrintB(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2)];

            Console.ForegroundColor = ConsoleColor.Yellow;

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (col == 0 ||
                        ((row == 0 || row == n / 2 || row == n - 1) && col < matrix.GetLength(1) - 1) ||
                        (col == matrix.GetLength(1) - 1 && row >= 1 && row < n / 2) ||
                        (col == matrix.GetLength(1) - 1 && row > n / 2 && row <= n - 2))
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }

        static void PrintL(int n, int heigth, int column)
        {
            string[,] matrix = new string[n, (n - 2) - 1];

            Console.ForegroundColor = ConsoleColor.Red;

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (col == (n - 2) / 2)
                    {
                        int num = next.Next(0, 10);

                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }

        static void PrintE(int n, int heigth, int column)
        {

            string[,] matrix = new string[n, (n - 2)];

            Console.ForegroundColor = ConsoleColor.Magenta;

            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                Console.SetCursorPosition(heigth, column++);

                for (int col = 0; col < matrix.GetLength(1); col++)
                {
                    if (row == 0 || row == n / 2 || row == n - 1)
                    {
                        int num = next.Next(0, 10);
                        Console.Write(num);
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine();
        }



    }
}
